*****************************************************************************************
* Figure A.12: Different Kernels for estimates
*****************************************************************************************

****************************************************************
* Voting 


use  "Data_temp/turnout.dta", clear

tab election, gen(elec_dummy)
drop elec_dummy1
gen rel_age=.

**************************************************************
* t0-t3

forvalues c = 0/3 {

	rdrobust voted age`c' if age`c'!=0, covs(elec_dummy*) p(1)  h(24) kernel(triangular)
		global eff_obs=e(N_h_l)+e(N_h_r)
	regsave RD_Estimate using "Data_temp/election_kernel_`c'_p1.dta", replace ci addlabel(elec, `c', kernel, 1)
	
	rdrobust voted age`c' if age`c'!=0, covs(elec_dummy*) p(1)  h(24) kernel(epanechnikov)
		global eff_obs=e(N_h_l)+e(N_h_r)
	regsave RD_Estimate using "Data_temp/election_kernel_`c'_p2.dta", replace ci addlabel(elec, `c', kernel, 2)

	rdrobust voted age`c' if age`c'!=0, covs(elec_dummy*) p(1)  h(24) kernel(uniform)
		global eff_obs=e(N_h_l)+e(N_h_r)
	regsave RD_Estimate using "Data_temp/election_kernel_`c'_p3.dta", replace ci addlabel(elec, `c', kernel, 3)
		}

* pooled 

* duplicate observations going into either estimate
gen m1=1 if inrange(age1,-48,47) & inrange(age2,-24,24)		
tab m1
expand 2 if m1==1, gen(dupl12)
replace age2=. if dupl12==1 // ignore those from duplicate observations
replace age1=. if dupl12==0 & inrange(age2,-24,24) //
count if inrange(age1,-48,47) & inrange(age2,-24,24)

gen m2=1 if inrange(age2,-24,24) & inrange(age3,-24,24)		
expand 2 if m2==1, gen(dupl23)
replace age2=. if dupl23==1
replace age3=. if dupl23==0 & inrange(age2,-24,24) 
count if inrange(age2,-24,24) & inrange(age3,-24,24)

forvalues x = 1/3 {
		replace rel_age=age`x' if inrange(age`x',-24,24) & rel_age==.
		}

rdrobust voted rel_age if rel_age!=0, covs(elec_dummy*) p(1)  h(24) kernel(triangular)
	global eff_obs=e(N_h_l)+e(N_h_r)
regsave RD_Estimate using "Data_temp/election_kernel_pooled_1.dta", replace ci addlabel(elec, 4, kernel, 1)

rdrobust voted rel_age if rel_age!=0, covs(elec_dummy*) p(1)  h(24) kernel(epanechnikov)
	global eff_obs=e(N_h_l)+e(N_h_r)
regsave RD_Estimate using "Data_temp/election_kernel_pooled_2.dta", replace ci addlabel(elec, 4, kernel, 2)

rdrobust voted rel_age if rel_age!=0, covs(elec_dummy*) p(1)  h(24) kernel(uniform)
	global eff_obs=e(N_h_l)+e(N_h_r)
regsave RD_Estimate using "Data_temp/election_kernel_pooled_3.dta", replace ci addlabel(elec, 4, kernel, 3)	
	
*****************************************
clear	
forvalues c=0/3 {
	forvalues p = 1/3 {
		append using "Data_temp/election_kernel_`c'_p`p'.dta"
		}
	}
forvalues p = 1/3 {
		append using "Data_temp/election_kernel_pooled_`p'.dta"
		}
	
	
	
sort elec kernel	
by elec: gen n=_n	
	
replace elec=elec-0.15 if n==1
replace elec=elec+0.15 if n==3
	
	
twoway (rcap ci_lo ci_up elec, lcolor(gs8) lwidth(medthin)) ///
(scatter coef elec if n==1,  msize(medlarge) msymbol(D) mfcolor(white) mlwidth(medthick) mlcolor(black)) ///
(scatter coef elec if n==2, msize(medlarge) msymbol(O) mfcolor(white) mlwidth(medthick) mlcolor(edkblue)) ///
(scatter coef elec if n==3, msize(medlarge) msymbol(T) mfcolor(white) mlwidth(medthick) mlcolor(edkblue)), ///
yl(-.1(0.1)0.6) xsc(r(-0.5 4.5))  xt("") ///
xlabel(none) legend(order(2 "Triangular" 3 "Epanechnikov" 4 "Uniform") row(1) size(small) ///
subtitle("Kernel", size(medsmall)) ) ///
subt("")   yt("RD estimate") ///
 xlab(0 "t{subscript:0}" 1 "t{subscript:1}" 2 "t{subscript:2}" 3 "t{subscript:3}" 4 `""t{subscript:1}-t{subscript:3}" "pooled""') ///
 xline(3.5, lwidth(thin) lcolor(gs12)) yline(0, lwidth(thin) lcolor(gs12) lpattern(solid)) ///
 graphregion(margin(zero))
graph export "Figures/a_fg12_a.eps", replace



**************************************************************
**************************************************************
* Political involvement


* t_0
foreach var in  index  party_closer1 interest_polit vote_agree vote_party  member_party  {
	dis "`var'"
	use "Data_temp/polit_involv.dta", clear
	
	cap drop dummy*
	
	qui tab year if `var'<. & inrange(age0,-24,24) & rel_year>=0, gen(dummy)
	drop dummy1
	
	rdrobust `var' age0 if age0!=0 & rel_year>=0, covs(dummy*) p(1)  h(24) kernel(triangular)
		regsave RD_Estimate using "Data_temp/election_kernel`var'_p1.dta", replace ci addlabel(elec, `c', kernel, 1)
		
	rdrobust `var' age0 if age0!=0 & rel_year>=0, covs(dummy*) p(1)  h(24) kernel(epanechnikov)
		regsave RD_Estimate using "Data_temp/election_kernel`var'_p2.dta", replace ci addlabel(elec, `c', kernel, 2)
		
	rdrobust `var' age0 if age0!=0 & rel_year>=0, covs(dummy*) p(1)  h(24) kernel(uniform)
		regsave RD_Estimate using "Data_temp/election_kernel`var'_p3.dta", replace ci addlabel(elec, `c', kernel, 3)		

		}

clear
gen n=.
local m=1
foreach var in index  party_closer1 interest_polit vote_agree vote_party member_party {
	forvalues x = 1/3 {
			append using "Data_temp/election_kernel`var'_p`x'.dta"
			replace n=`m' if n==.
			}	
			local ++m
		}		


replace n=n-0.15 if kernel==1
replace n=n+0.15 if kernel==3

		
		

twoway (rcap ci_lo ci_up n, lcolor(gs8) lwidth(medthin)) ///
		(scatter coef n if kernel==1,  msize(medlarge) msymbol(D) mfcolor(white) mlwidth(medthick) mlcolor(black)) ///
		(scatter coef n if kernel==2, msize(medlarge) msymbol(O) mfcolor(white) mlwidth(medthick) mlcolor(edkblue)) ///
		(scatter coef n if kernel==3, msize(medlarge) msymbol(T) mfcolor(white) mlwidth(medthick) mlcolor(edkblue)), ///
		yl(-.05(0.05)0.2) xsc(r(0.7 6.3))  xt("") ///
		xlabel(none)  legend(order(2 "Triangular" 3 "Epanechnikov" 4 "Uniform") row(1) size(small) ///
subtitle("Kernel", size(medsmall)) ) ///
		subt("")  yt("RD estimate") ///
		 xlab(1 `""Index of" "political involvement""' 2 `""Supporting or close" "to one party""' ///
		 3 `""Interested in" "politics""' 4 `""Voting as a" "social norm""' 5 `""States a party" "to vote for""' 6 `""Member of a" "political party""', ///
		labsize(*0.9) ) graphregion(margin(zero)) ///
		yline(0, lwidth(thin) lcolor(gs12) lpattern(solid))
	graph export "Figures/a_fg12_b.eps", replace
		
		
		
* t_1 - t_3 pooled
foreach var in  index  party_closer1 interest_polit vote_agree vote_party member_party { // 

	use "Data_temp/polit_involv.dta", clear

	cap drop dummy*
	qui tab year if `var'<. & inrange(rel_age2,-24,24) & rel_year>=0, gen(dummy)
		drop dummy1
	
rdrobust `var' rel_age2 if rel_age2!=0, covs(dummy*) p(1)  h(24) kernel(triangular)
		regsave RD_Estimate using "Data_temp/electionpoolkernel`var'_p1.dta", replace ci addlabel(elec, `c', kernel, 1)
		
	rdrobust `var' rel_age2 if rel_age2!=0, covs(dummy*) p(1)  h(24) kernel(epanechnikov)
		regsave RD_Estimate using "Data_temp/electionpoolkernel`var'_p2.dta", replace ci addlabel(elec, `c', kernel, 2)
		
	rdrobust `var' rel_age2 if rel_age2!=0, covs(dummy*) p(1)  h(24) kernel(uniform)
		regsave RD_Estimate using "Data_temp/electionpoolkernel`var'_p3.dta", replace ci addlabel(elec, `c', kernel, 3)		
		}		
	

	
clear
gen n=.
local m=1
foreach var in index  party_closer1 interest_polit vote_agree vote_party member_party {
	forvalues x = 1/3 {
			append using "Data_temp/electionpoolkernel`var'_p`x'.dta"
			replace n=`m' if n==.
			}	
			local ++m
		}		


replace n=n-0.15 if kernel==1
replace n=n+0.15 if kernel==3

		
		

twoway (rcap ci_lo ci_up n, lcolor(gs8) lwidth(medthin)) ///
		(scatter coef n if kernel==1,  msize(medlarge) msymbol(D) mfcolor(white) mlwidth(medthick) mlcolor(black)) ///
		(scatter coef n if kernel==2, msize(medlarge) msymbol(O) mfcolor(white) mlwidth(medthick) mlcolor(edkblue)) ///
		(scatter coef n if kernel==3, msize(medlarge) msymbol(T) mfcolor(white) mlwidth(medthick) mlcolor(edkblue)), ///
		yl(-.1(0.05)0.15) xsc(r(0.7 6.3))  xt("") ///
		xlabel(none)  legend(order(2 "Triangular" 3 "Epanechnikov" 4 "Uniform") row(1) size(small) ///
subtitle("Kernel", size(medsmall)) ) ///
		subt("")  yline(-.1 -.05 0 .05 0.1 .15, lcolor(gs15*0.8) lpattern(dash)) yt("RD estimate") ///
		 xlab(1 `""Index of" "political involvement""' 2 `""Supporting or close" "to one party""' ///
		 3 `""Interested in" "politics""' 4 `""Voting as a" "social norm""' 5 `""States a party" "to vote for""' 6 `""Member of a" "political party""', ///
		labsize(*0.9) )   graphregion(margin(zero)) ///
		yline(0, lwidth(thin) lcolor(gs12) lpattern(solid))
	graph export "Figures/a_fg12_c.eps", replace
		
		